const loginIdValidator = new FieldValidator('txtLoginPwd',function(val){
    if(!val){
        return '请填写账号'
    }
}) 

const loginPwdValidator = new FieldValidator('txtLoginPwd',function(val){
    if(!val){
        return '请填写密码'
    }
}) 
const form = document.querySelector(".user-form")
form.onsubmit=async(e)=>{
    e.preventDefault()
    const result = await FieldValidator.validate(loginIdValidator,loginPwdValidator)
    if(!result) return
    const formData = new FormData(form)
    const data = Object.fromEntries(formData.entries())
    const res = await API.login(data)
    if(res.code === 0){
        alert("登录成功，点击确认进入首页")
        location.href = './index.html'
    }else{
        loginIdValidator.p.innerText = '账号或密码错误';
        loginPwdValidator.input.value = '';
    }

}